function term = Welfare(Gdest,Gunc,ccp,s_0,f_0,m_0,c_u,c_s,c_inv,K_obs,ksi,r,E,sigma,Jf,W,U)

g_euler = 0.5772;

M = 15;
q = m_0.*Gdest;
b = (s_0-m_0).*ccp;
b(eye(M)==1) = nan;
q(eye(M)==1) = nan;

terms = zeros(8,1);

terms(1) = nansum(q(:).*(r(:)-K_obs(:))); %customers value - entry costs

terms(2) = -nansum(q(:).*c_s(:)./ksi(:)); %cost of traveling for loaded carriers

terms(3) = -nansum(b(:).*c_s(:)./ksi(:)); %cost of traveling for empty carriers

terms(4) = -nansum(s_0.*c_u); %search costs for waiting carriers

terms(5) = -sum(f_0.*c_inv); %inventory costs for waiting customers

k1 = ccp; %logit component of carriers' utility
k1 = k1.*log(k1);
k1 = sum(k1,2);
term(6) = -sum((s_0-m_0).*k1)./sigma;
term(6) = term(6) + sum(s_0-m_0)*g_euler./sigma;

k1 = Gunc; %logit component of customers' utility
k1 = k1.*log(k1);
k1 = nansum(k1,2);
term(7) = -sum(E.*k1);

end
